import { notification } from 'ant-design-vue';
/**
 * @description: 提示
 * @param {*} type 类型： success info warning error
 * @param {*} msg 提示内容
 * @return {*}
 */
function openNotification(type, msg) {
    notification[type]({
        message: "系统提示",
        description: msg,
    });
}

export function toast(msg) {
    openNotification("success", msg)
}

toast.fail = (msg) => {
    return openNotification("error", msg)
}

/**
 * @description: 将base64转换为文件
 * @param {*} dataurl base64格式
 * @param {*} filename 文件名
 * @return {*}
 */
export function dataURLtoFile(dataurl, filename) {

    let arr = dataurl.split(","),
        mime = arr[0].match(/:(.*?);/)[1],
        bstr = atob(arr[1]),
        n = bstr.length,
        u8arr = new Uint8Array(n);
    while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
    }
    return new File([u8arr], filename, { type: mime });
}

/**
 * @description: 数字格式化为金额（逗号隔开）
 * @param {*} s 需要格式化的值
 * @param {*} n 需要保留的位数
 * @return {*}
 */
export function fmoney(s, n = 2) {
    n = n > 0 && n <= 20 ? n : 2;
    s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
    let l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];
    let t = "";
    for (let i = 0; i < l.length; i++) {
        t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
    }
    return t.split("").reverse().join("") + "." + r;
}

export function downloadHtml(html) {
    var blob = new Blob([html], { type: 'text/html' });
    var url = window.URL.createObjectURL(blob);
    var a = document.createElement('a');
    a.href = url;
    a.style.display = 'none';
    a.download = "demo.html";
    a.click();
}












